﻿
namespace Service
{
    using Data.Repository;
    using System.Linq;
	using System.Collections.Generic;

    public class ProductAdditionalPropertyService : IProductAdditionalPropertyService
    {
        private IProductAdditionalPropertyRepository _productAdditionalPropertyRepository;

        #region IProductAdditionalPropertyService Members

        public int CreateNewProductAdditionalProperty(Data.Entity.ProductAdditionalProperty theNewProductAdditionalProperty)
        {
            if (theNewProductAdditionalProperty == null)
            {
                return 0;
            }

            if (_productAdditionalPropertyRepository == null)
            {
                _productAdditionalPropertyRepository = new ProductAdditionalPropertyRepository();
            }

            return _productAdditionalPropertyRepository.CreateNewProductAdditionalProperty(theNewProductAdditionalProperty);
        }

        public IList<Data.Entity.ProductAdditionalProperty> GetProductAdditionalProperties(int productID)
        {
            if (productID <= 0)
            {
                return null;
            }

            if (_productAdditionalPropertyRepository == null)
            {
                _productAdditionalPropertyRepository = new ProductAdditionalPropertyRepository();
            }

            return _productAdditionalPropertyRepository.GetProductAdditionalProperties(productID);
        }

        public int UpdateProductAdditionalProperty(Data.Entity.ProductAdditionalProperty theProductAdditionalProperty)
        {
            if (theProductAdditionalProperty == null || theProductAdditionalProperty.ProductAdditionalPropertyID <= 0)
            {
                return 0;
            }

            if (_productAdditionalPropertyRepository == null)
            {
                _productAdditionalPropertyRepository = new ProductAdditionalPropertyRepository();
            }

            return _productAdditionalPropertyRepository.UpdateProductAdditionalProperty(theProductAdditionalProperty);
        }

		public bool DeleteProductAdditionalProperty(int id)
		{
			if(id <= 0)
			{
				return false;
			}

			if(_productAdditionalPropertyRepository == null)
			{
				_productAdditionalPropertyRepository = new ProductAdditionalPropertyRepository();
			}

			return _productAdditionalPropertyRepository.DeleteProductAdditionalProperty(id);
		}

		public void SaveTheCustomerMustKnownContent(Data.Entity.ProductAdditionalProperty theCustomerMustKnownContent)
		{
			if(theCustomerMustKnownContent == null)
			{
				return;
			}

			if(_productAdditionalPropertyRepository == null)
			{
				_productAdditionalPropertyRepository = new ProductAdditionalPropertyRepository();
			}

			_productAdditionalPropertyRepository.SaveTheCustomerMustKnownContent(theCustomerMustKnownContent);
		}

		public Data.Entity.ProductAdditionalProperty GetTheProductAdditionalPropertyByName(string propertyName)
		{
			if (string.IsNullOrEmpty(propertyName))
			{
				return null;
			}

			if (_productAdditionalPropertyRepository == null)
			{
				_productAdditionalPropertyRepository = new ProductAdditionalPropertyRepository();
			}

			return _productAdditionalPropertyRepository.GetTheProductAdditionalPropertyByName(propertyName);
		}

		#endregion
	}
}
